﻿package com.amcharts
{
    import com.amcharts.axes.*;
    import com.amcharts.chartClasses.*;
    import com.amcharts.geom.*;
    import com.amcharts.utils.*;
    import flash.display.*;
    import mx.collections.*;
    import mx.styles.*;

    public class AmRadarChart extends AmCoordinateChart
    {
        protected var _radius:Number;
        static const VERSION:String = "1.8.3.1";
        private static var stylesInited:Boolean = initStyles();

        public function AmRadarChart()
        {
            return;
        }// end function

        public function get radarRadius() : Number
        {
            return _radius;
        }// end function

        override protected function designMode() : void
        {
            dataProvider = new ArrayCollection([{axis:"sample 1", value:1}, {axis:"sample 2", value:3}, {axis:"sample 3", value:6}, {axis:"sample 4", value:4}, {axis:"sample 5", value:5}]);
            categoryField = "axis";
            var _loc_1:* = new AmGraph();
            _loc_1.valueField = "value";
            addGraph(_loc_1);
            return;
        }// end function

        override protected function createChart() : void
        {
            var _loc_5:ValueAxis = null;
            var _loc_6:AmGraph = null;
            this.setChildIndex(_valueAxesContainer, (this.numChildren - 1));
            this.setChildIndex(_valuesContainer, (this.numChildren - 1));
            this.setChildIndex(_graphsContainer, (this.numChildren - 1));
            this.setChildIndex(_labelsContainer, (this.numChildren - 1));
            if (_amchartsLink)
            {
                this.setChildIndex(_amchartsLink, (this.numChildren - 1));
            }
            this.setChildIndex(_balloon, (this.numChildren - 1));
            _radius = Utils.toCoordinate(getStyle("radius") as String, this.width, this.height);
            var _loc_1:* = this.width / 2;
            var _loc_2:* = this.height / 2;
            _valueAxesContainer.x = _loc_1;
            _valueAxesContainer.y = _loc_2;
            _valuesContainer.x = _loc_1;
            _valuesContainer.y = _loc_2;
            _labelsContainer.x = _loc_1;
            _labelsContainer.y = _loc_2;
            _graphsContainer.x = _loc_1;
            _graphsContainer.y = _loc_2;
            Utils.removeChildren(_valueAxesContainer);
            var _loc_3:* = _valueAxes.length;
            var _loc_4:Number = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_5 = _valueAxes[_loc_4];
                _loc_5.width = _radius;
                _loc_5.height = _radius;
                _valueAxesContainer.addChild(_loc_5);
                _loc_4 = _loc_4 + 1;
            }
            _loc_3 = _graphs.length;
            _loc_4 = 0;
            while (_loc_4 < _loc_3)
            {
                
                _loc_6 = _graphs[_loc_4];
                _loc_6.chartType = "radar";
                _loc_6.width = _radius;
                _loc_6.height = _radius;
                _loc_6.index = _loc_4;
                _loc_6.type = "line";
                _graphsContainer.addChildAt(_loc_6, 0);
                chooseGraphColor(_loc_6, _loc_4);
                _loc_4 = _loc_4 + 1;
            }
            createPlotArea();
            dispatchDataUpdatedEvent();
            return;
        }// end function

        override protected function updateData() : void
        {
            var _loc_4:ValueAxis = null;
            var _loc_5:AmGraph = null;
            super.updateData();
            _dataParser.charts = [this];
            _dataParser.categoryField = _categoryField;
            _chartDataProvider = _dataParser.parseSerialData(_dataProvider);
            var _loc_1:* = _chartDataProvider.length - 1;
            var _loc_2:* = _valueAxes.length;
            var _loc_3:Number = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_4 = _valueAxes[_loc_3];
                _loc_4.dataProvider = _chartDataProvider;
                _loc_4.zoom(0, _loc_1);
                _loc_3 = _loc_3 + 1;
            }
            _loc_2 = _graphs.length;
            _loc_3 = 0;
            while (_loc_3 < _loc_2)
            {
                
                _loc_5 = _graphs[_loc_3];
                _loc_5.chartDataProvider = _chartDataProvider;
                _loc_5.zoom(0, _loc_1);
                _loc_3 = _loc_3 + 1;
            }
            return;
        }// end function

        public function get categoryField() : String
        {
            return _categoryField;
        }// end function

        protected function createPlotArea() : void
        {
            var _loc_5:Sprite = null;
            var _loc_6:ValueAxis = null;
            var _loc_7:String = null;
            var _loc_8:Sprite = null;
            var _loc_9:Number = NaN;
            var _loc_10:Sprite = null;
            var _loc_11:Array = null;
            var _loc_12:Array = null;
            var _loc_13:Number = NaN;
            var _loc_14:Number = NaN;
            var _loc_1:* = this.getStyle("plotAreaFillAlphas");
            var _loc_2:* = this.getStyle("plotAreaFillColors");
            var _loc_3:* = this.getStyle("plotAreaBorderColor");
            var _loc_4:* = this.getStyle("plotAreaBorderAlpha");
            if (_loc_1.length > 0)
            {
                _loc_5 = new Rect(_radius * 2, _radius * 2, _loc_2, _loc_1, 0, 0, 0, 0, 0, GradientType.RADIAL);
                _loc_5.x = -_radius;
                _loc_5.y = -_radius;
                _loc_6 = _valueAxes[0];
                _loc_7 = _loc_6.getStyle("gridType");
                if (_loc_4 > 0)
                {
                    _loc_10 = new Sprite();
                    _loc_10.graphics.lineStyle(0, _loc_3, _loc_4);
                    _valueAxesContainer.addChildAt(_loc_10, 0);
                }
                if (_loc_7 == "polygons")
                {
                    _loc_11 = new Array();
                    _loc_12 = new Array();
                    _loc_9 = _chartDataProvider.length;
                    _loc_13 = 0;
                    while (_loc_13 < _loc_9)
                    {
                        
                        _loc_14 = 180 - 360 / _loc_9 * _loc_13;
                        _loc_11.push(_radius * Math.sin(_loc_14 / 180 * Math.PI));
                        _loc_12.push(_radius * Math.cos(_loc_14 / 180 * Math.PI));
                        _loc_13 = _loc_13 + 1;
                    }
                    _loc_11.push(_loc_11[0]);
                    _loc_12.push(_loc_12[0]);
                    _loc_8 = new Polygon(_loc_11, _loc_12, [0], [1]);
                    if (_loc_4 > 0)
                    {
                        _loc_10 = new Polygon(_loc_11, _loc_12, [0], [0], 0, _loc_3, _loc_4);
                        _valueAxesContainer.addChildAt(_loc_10, 0);
                    }
                }
                else
                {
                    _loc_8 = new Sprite();
                    _loc_8.graphics.beginFill(1, 1);
                    _loc_8.graphics.drawCircle(0, 0, _radius);
                    if (_loc_4 > 0)
                    {
                        _loc_10.graphics.drawCircle(0, 0, _radius);
                    }
                }
                _valueAxesContainer.addChildAt(_loc_8, 0);
                _valueAxesContainer.addChildAt(_loc_5, 0);
                _loc_5.mask = _loc_8;
            }
            return;
        }// end function

        override protected function setAxisRenderers(param1:AxisBase) : void
        {
            param1.axisItemRenderer = RadarAxisItemRenderer;
            param1.axisRenderer = RadarAxisRenderer;
            param1.guideFillRenderer = RadarAxisGuideFillRenderer;
            return;
        }// end function

        public function set categoryField(param1:String) : void
        {
            _categoryField = param1;
            _dataChanged = true;
            invalidateProperties();
            invalidateDisplayList();
            return;
        }// end function

        private static function initStyles() : Boolean
        {
            var styleDeclaration:* = StyleManager.getStyleDeclaration("AmRadarChart");
            if (!styleDeclaration)
            {
                styleDeclaration = new CSSStyleDeclaration();
            }
            styleDeclaration.defaultFactory = function () : void
            {
                this.radius = "35%";
                return;
            }// end function
            ;
            StyleManager.setStyleDeclaration("AmRadarChart", styleDeclaration, false);
            return true;
        }// end function

    }
}
